package com.iwuke.dance.util;

import android.content.Context;
import android.widget.Toast;

import com.iwuke.dance.activity.LPWHApplication;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;

/**
 * @author: 魏从响
 * @date: 2025/9/18
 */
public class WeChatPayUtil {
    public static void startPayment(Context context, String appId, String partnerId
            , String prepayId, String packageValue, String nonceStr, String timeStamp, String sign) {
        IWXAPI wxApi = ((LPWHApplication) context.getApplicationContext()).getWxApi();

        // 验证微信是否安装
        if (!wxApi.isWXAppInstalled()) {
            Toast.makeText(context, "未安装微信客户端", Toast.LENGTH_SHORT).show();
            return;
    }

        // 构建支付请求（参数需由服务器生成）
        PayReq request = new PayReq();
        request.appId = appId; //YOUR_APP_ID
        request.partnerId = partnerId;  // 微信支付分配的商户号  商户号
        request.prepayId = prepayId;  // 预支付交易会话ID（服务器返回）
        request.packageValue = packageValue;  // 固定值
        request.nonceStr = nonceStr;  // 服务器生成 随机字符串
        request.timeStamp = timeStamp;//String.valueOf(System.currentTimeMillis() / 1000)
        request.sign = sign;

//        LogUtil.logD("支付请求",new Gson().toJson(request));
        // 发送支付请求
        wxApi.sendReq(request);
    }
}
